package cn.gok;

import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName homework
 * @Description TODO
 * @Author HP
 * @Date 14:58 2022/7/7
 * @Version 1.0
 **/
public class homework {
    public static void 大数运算(){
        BigDecimal b1 = new BigDecimal(7777777.7777);
        BigDecimal b2 = new BigDecimal(3.333333);
        BigDecimal result = b1.divide(b2,2, RoundingMode.HALF_UP);
        System.out.println("7777777.7777/3.333333 (保留2位小数，四舍五入的结果为): "+result);
    }
    public static void 生日(){
        Calendar calendar = Calendar.getInstance();
        calendar.set(2001,4,29);
        calendar.add(Calendar.DATE,-7);
        int n = calendar.get(Calendar.DAY_OF_WEEK);
        int i = 0;
        if (n>3){
            i=-(n-3);
            calendar.add(Calendar.DATE,i);
            System.out.println("前一周的周四是该年的第"+calendar.get(Calendar.DAY_OF_YEAR)+"天");
        }else if (n<3) {
            i=3-n;
            calendar.add(Calendar.DATE,i);
            System.out.println("前一周的周四是该年的第"+calendar.get(Calendar.DAY_OF_YEAR)+"天");
        }else {
            System.out.println("前一周的周四是该年的第"+calendar.get(Calendar.DAY_OF_YEAR)+"天");
        }

    }
    public static void showJava(File file){
        File file1[]=file.listFiles();
        for(File file2:file1){
            if(file2.isFile()) {
                if (file2.getPath().endsWith(".java"))
                System.out.println(file2.getAbsolutePath());
            }else if(file2.isDirectory()){
                showJava(file2);
            }
        }
    }


    private static void copyTest() throws IOException {
        File file = new File("C:\\Users\\user\\Desktop\\resp1\\day4\\src\\cn\\gok\\homework\\HelooWorld.txt");
        if (!file.exists()){
            System.out.println(file.createNewFile());
        }
        if (file.isFile()){
            File file2=new File("C:\\Users\\user\\Desktop\\resp1\\day4\\src\\cn\\gok\\homework\\IOTest");
            file2.mkdir();
            Reader re = new FileReader("C:\\Users\\user\\Desktop\\resp1\\day4\\src\\cn\\gok\\homework\\HelooWorld.txt");
            Writer wr = new FileWriter("C:\\Users\\user\\Desktop\\resp1\\day4\\src\\cn\\gok\\homework\\IOTest\\a.txt");
            char c2[] = new char[100];
            int len=0;
            while ((len=re.read(c2))!=-1){
                String string = new String(c2,0,len);
                wr.write(string);
            }
            System.out.println("复制成功");
            wr.close();
            re.close();


        }


    }


    private static void 编码转换() throws IOException {
        InputStreamReader isr=new InputStreamReader(new FileInputStream("C:\\Users\\user\\Desktop\\resp1\\day4\\src\\cn\\gok\\homework\\HelooWorld.txt"),"utf-8");
        char bs[]=new char[10];
        int len=0;
        String string = new String();
        while(((len = isr.read(bs)) !=-1)){
            string = new String(bs,0,len);
        }
        isr.close();
        OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("C:\\Users\\user\\Desktop\\resp1\\day4\\src\\cn\\gok\\homework\\c.txt"),"GBK");
        osw.write(string);
        osw.close();
        System.out.println("从UTF-8转换成GBK");
    }


    public static void main(String[] args) throws IOException {
        大数运算();
        System.out.println("------------------------------------------------------------");
        生日();
        System.out.println("------------------------------------------------------------");
        File file=new File("C:\\Users\\user\\Desktop\\resp1\\day4");
        showJava(file);
        System.out.println("------------------------------------------------------------");
        copyTest();
        编码转换();
    }


}
